# 比较不同并查集实现
import random
import time
from union_find import UnionFind
from union_find2 import UnionFind2
from union_find3 import UnionFind3
from union_find4 import UnionFind4
from union_find5 import UnionFind5
from union_find6 import UnionFind6


def perf(uf, n):

    random.seed(time.time())

    start = time.perf_counter()

    for i in range(n):
        a = random.randrange(1, n)
        b = random.randrange(1, n)
        uf.union(a, b)

    for i in range(n):
        a = random.randrange(1, n)
        b = random.randrange(1, n)
        uf.is_connected(a, b)
    
    end = time.perf_counter()
    print("Took %.2f secs" % (end - start))


if __name__ == '__main__':
    n = 10000
    perf(UnionFind(n), n)
    perf(UnionFind2(n), n)
    perf(UnionFind3(n), n)
    perf(UnionFind4(n), n)
    perf(UnionFind5(n), n)
    perf(UnionFind6(n), n)